# +----------------------------------------------------------------------
# | ChatWork智能聊天办公系统
# +----------------------------------------------------------------------
# | 软件声明: 本系统并非自由软件,未经授权任何形式的商业使用均属非法。
# | 版权保护: 任何企业和个人不允许对程序代码以任何形式任何目的复制/分发。
# | 授权要求: 如有商业使用需求,请务必先与版权所有者取得联系并获得正式授权。
# +----------------------------------------------------------------------
# | Author: ChatWork Team <2474369941@qq.com>
# +----------------------------------------------------------------------
from typing import List
from fastapi import APIRouter, Request, Depends
from hypertext import R, response_json
from apps.admin.schemas.auth import menu_schema as schema
from apps.admin.service.auth.menu_service import MenuService

router = APIRouter(prefix="/menu", tags=["权限菜单"])


@router.get("/whole", summary="所有菜单", response_model=R[List[schema.AuthMenuWholeVo]])
@response_json
async def whole():
    return await MenuService.whole()


@router.get("/routes", summary="菜单路由", response_model=R[List[schema.AuthMenuRoutesVo]])
@response_json
async def routes(request: Request):
    admin_id: int = request.state.admin_id
    role_id: int = request.state.role_id
    return await MenuService.routes(admin_id, role_id)


@router.get("/lists", summary="菜单列表", response_model=R[List[schema.AuthMenuListVo]])
@response_json
async def lists():
    return await MenuService.lists()


@router.get("/detail", summary="菜单详情", response_model=R[schema.AuthMenuDetailVo])
@response_json
async def detail(params: schema.AuthMenuDetailIn = Depends()):
    return await MenuService.detail(params.id)


@router.post("/add", summary="菜单新增", response_model=R)
@response_json
async def add(params: schema.AuthMenuAddIn):
    return await MenuService.add(params)


@router.post("/edit", summary="菜单编辑", response_model=R)
@response_json
async def edit(params: schema.AuthMenuEditIn):
    return await MenuService.edit(params)


@router.post("/delete", summary="菜单删除", response_model=R)
@response_json
async def delete(params: schema.AuthMenuDeleteIn):
    return await MenuService.delete(params.id)
